<#assign ctx=request.contextPath />
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>注册</title>
    <!-- CSS文件 -->
    <link href="${ctx}/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css" rel="stylesheet">
    <!--layui-->
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">

<#-- mystyle -->
    <link href="${ctx}/css/register.css" rel="stylesheet">
</head>

<body>
<header>
    <div class="header_content">
        <span class="platformName">数众科技</span>
    </div>
</header>
<form class="layui-form layui-form-pane">
    <div class="mainContent">
        <div class="logoBox">
            <span class="platformRegister">权限修改</span>
        </div>
        <div class="list">
            <span>账号</span>
            <input type="text" name="username" disabled value="${user.username}" class="form-control"
                   lay-verify="required"/>
        </div>
        <input hidden name="id" value="${user.id}">
        <div class="list">
            <span>权限</span>
            <select class="form-control" name="role">
                <option value="2" <#if user.role==2>selected</#if>>管理员</option>
                <option value="3" <#if user.role==3>selected</#if>>普通用户</option>
            </select>
        </div>
        <div class="list SubmitBtnBox">
            <span>&nbsp;</span>
            <button id="saveBtn" class="btn btn-w-m btn-primary" lay-submit lay-filter="formSave">提交</button>
            &nbsp;&nbsp;&nbsp;
            <a href="${ctx}/userList" class="btn btn-w-m btn-default">返回</a>
        </div>
    </div>
</form>
</body>
<script src="${ctx}/js/jquery.min.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        form.on('submit(formSave)', function (data) {
            var obj = data.field;
            console.log(obj);
            if (obj.password != obj.password2) {
                layer.msg("两次密码不一致", {icon: 5});
                return false;
            }
            $.ajax({
                url: '${ctx}/updateUserRole',
                type: "post",
                data: obj,
                success: function (res) {
                    if (res.status == 0) {
                        window.location.href = "${ctx}/userList";
                    } else {
                        layer.msg(res.msg, {icon: 5})
                    }

                }
            });
            return false;
        });
        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
        });
    })
</script>
</html>
